import React, { useState, useEffect } from 'react'
import { View, RichText } from '@tarojs/components'
import { AtList, AtListItem, AtButton, AtToast } from "taro-ui"
import Taro, {  useShareAppMessage,useShareTimeline} from '@tarojs/taro'
import ToLogin from '../../compontents/toLogin'
import api from '../../http/api'
import lhTool from 'lh-tool'



import './index.less'
import "taro-ui/dist/style/components/list.scss";
import "taro-ui/dist/style/components/icon.scss";
import "taro-ui/dist/style/components/modal.scss";
import "taro-ui/dist/style/components/button.scss";
import "taro-ui/dist/style/components/toast.scss";


export default (props: any) => {
  const id:any = props.tid.split('id=')[1].split('&')[0]
  const [data,setData]:any = useState({"id":33,"uSchoolId":1,"src":"https://static.zhongningwenhua.com/uniSchool/upload/a59b217e026c3a4df82ef88eaab02699.png","title":"一展拼搏活力，乐在趣味赛场","intro":"湖科活力校园","activeTime":"2020-12-19T10:30:30.000Z","address":"湖北科技学院行政楼团辅导室","content":"<p><img style='width:100%' src=\"https://static.zhongningwenhua.com/uniSchool/upload/e6c3ceedf0399d064366621a0fa147e1.png\" style=\"max-width:100%;\" width=\"100%\"><br></p>","type":1,"manageId":11,"isGrounding":1,"publishTime":"2020-12-24T04:31:59.000Z","ord":0})
  useEffect(()=>{
    api.version().then((res:any)=>{
      const version = res.data
      if (version === 1) {
        api.activeDetail({
          id:id,
        }).then((res:any)=>{
          const _data =  res.data
          _data.content = _data.content.replace(/<img/g,"<img style='width:100%'")
          setData(_data)
        })
      }
    })
    
  },[])
  useShareAppMessage(res => {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: `U你校园活动详情${data.title}`,
      path: `/pages/activeDetail/index?id=${id}`
    }
  })
  useShareTimeline(()=>{
    return {
      title: `U你校园活动详情${data.title}`,
      path: `/pages/activeDetail/index?id=${id}`
    }
  })
  return (
    <View className='activeDetail'>
      <ToLogin url='/pages/activeDetail/index'></ToLogin>
      <View className='title'>
      <View className='txt'>{data.title}</View>
        <View className='time'>发布时间：{lhTool.formatDate.format(new Date(data.publishTime),'yyyy/MM/dd hh:mm:ss')}</View>
        <View className='time'>活动地址：{data.address}</View>
        <View className='time'>活动时间：{lhTool.formatDate.format(new Date(data.activeTime),'yyyy/MM/dd hh:mm:ss')}</View>
      </View>
      <View className='content'>
        <RichText className='contRich'  nodes={data.content}/>
      </View>  
      {/* <View className='getCard'>
        <View className='shareW'>
          <View className='at-icon at-icon-share'></View>
          <View className='share'>分享</View> 
        </View>
      </View> */}
    </View>
  )
}
